#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <iostream>
using namespace std;

#define TRACE(x...) 
#define PRINT(x...) TRACE(printf(x))
#define WATCH(x) TRACE(cout << #x << " = " << x << endl)

#define rep(i,n) for (int i=0; i<n; i++)
#define repi(i,a,b) for (int i=a; i<b; i++)

#define f first
#define s second
#define mp make_pair

#define ll long long
#define INF 0x3f3f3f3f
#define NINF 0xc0c0c0c0

#define sqr(x) ((x)*(x))

int n,m;
int k;
char shelf[45][45][15];
int op, x, y;
char id[15];
int fl;

int main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	scanf("%d %d %d", &n, &m, &k);
	rep(i,n) rep(j,m) strcpy(shelf[i][j], "");

	rep(o,k) {
		scanf("%d", &op);
		if (op==1) {
			scanf("%d %d %s", &x, &y, id);
			PRINT("Trying to put %s in %d, %d\n", id, x, y);
			x--; y--;
			fl=0;
			
			repi(j,y,m) {
				if (!strcmp(shelf[x][j], "")) {
					strcpy(shelf[x][j], id);
					PRINT("Put %s in %d, %d\n", id, x, j);
					fl=1; break;
				}
			}

			repi(i,x+1,n) {
				if (fl) break;

				rep(j,m) {
					if (!strcmp(shelf[i][j], "")) {
						strcpy(shelf[i][j], id);
						PRINT("Put %s in %d, %d\n", id, i, j);
						fl=1; break;
					}
				}
			}
		}

		else {
			scanf("%s", id);
			PRINT("Removing %s\n", id);
			fl=0;

			rep(i,n) {
				rep(j,m)  {
					if (!strcmp(shelf[i][j], id)) {
						strcpy(shelf[i][j], "");
						printf("%d %d\n", i+1, j+1);
						fl=1; break;
					}
				}

				if (fl) break;
			}

			if (!fl) printf("-1 -1\n");
		}

		TRACE(
			rep(i,n) {
				rep(j,m) if (strcmp(shelf[i][j], "")) {
					printf("%d, %d: %s\n", i, j, shelf[i][j]);
				}  
			}
		)	
	}

	return 0;
}
